package com.caiyi.financial.nirvana.sms.service;

import com.caiyi.financial.nirvana.sms.base.service.BaseService;
import com.caiyi.financial.nirvana.sms.entity.SmsMsg;
import com.caiyi.financial.nirvana.sms.mapper.SmsMsgMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class SmsMsgService extends BaseService<SmsMsg> {

    @Autowired
    private SmsMsgMapper smsMsgMapper;

    /**
     * * 插入list
     *
     * @param list list
     */
    @Transactional
    public void insertList(List<SmsMsg> list) {
        int res = smsMsgMapper.insertList(list);
        logger.info("InsertMesssageQueue insertList size : {} , insert into return {}", list.size(), res);
        if (res != list.size()) {
            logger.error("InsertMesssageQueue DB Insert Error.");
        }
    }

    /**
     * 根据MessageId更新msg
     *
     * @param smsMsg msg
     * @return 影响行数
     */
    public int updateByMessageId(SmsMsg smsMsg) {
        Example example = new Example(SmsMsg.class);
        example.createCriteria().andEqualTo("messageId", smsMsg.getMessageId())
                .andLessThanOrEqualTo("status", smsMsg.getStatus());
        return this.smsMsgMapper.updateByExampleSelective(smsMsg, example);
    }


}
